package com.linglingC.controller;


import com.linglingC.pojo.Emplyee;
import com.linglingC.pojo.PageBean;
import com.linglingC.pojo.Result;
import com.linglingC.service.EmplyeeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

@Slf4j
@RestController
public class EmplyeeContrroller {

    @Autowired
    private EmplyeeService emplyeeService;


    @GetMapping("/emplyeeFindAll")
    public Result emplyeeFindAll(@RequestParam(defaultValue = "1") Integer page,
                                 @RequestParam(defaultValue = "10") Integer pageSize
                                             ){
        log.info("员工表分页查询:{} {}",page,pageSize);

        PageBean pageBean=emplyeeService.findAll(page,pageSize);

        return Result.success(pageBean);
    }

    @GetMapping("/empSelect")
    public Result empSelect(String key,String value,@RequestParam(defaultValue = "1") Integer page,
                            @RequestParam(defaultValue = "10") Integer pageSize){
        log.info("员工表条件: 字段:{} 值:{}",key,value );

        PageBean pageBean=emplyeeService.select(key,value,page,pageSize);

        return  Result.success(pageBean);
    }

    @PostMapping("/inserEmp")
    private Result insertEmp(@RequestBody Emplyee emplyee){
        log.info("添加员工: {}",emplyee);
        emplyeeService.addEmplyee(emplyee);
        return Result.success();
    }

    @DeleteMapping("/empDelete/{ID}")
    private Result empDelete(@PathVariable Integer ID){
        log.info("删除单一员工: ID: {}",ID);
        emplyeeService.deleteOneEmplyee(ID);
        return Result.success("删除成功");
    }

    @PutMapping("/editEmp")
    public Result editEmp(@RequestBody Emplyee emplyee){
        log.info("修改员工信息: {}",emplyee);
        emplyeeService.editEmplyee(emplyee);
        return Result.success();
    }

}
